#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMenu>
#include <QAction>
#include <QContextMenuEvent>
#include <QCursor>
#include <QMouseEvent>
#include <QPoint>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QList>
#include <QMap>
#include <QEvent>
#include "weathernetwork.h"

class Widget : public QWidget
{
    Q_OBJECT

friend class WeatherNetWork;
public:
    Widget(QWidget* parent = nullptr);
    ~Widget();

protected:
    void contextMenuEvent(QContextMenuEvent* event) override;
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    bool eventFilter(QObject* watched, QEvent* event) override;

private:
    void initTop();
    void initLeft();
    void initRight();
    void drawLowTempCurve();
    void drawHighTempCurve();

    QMenu* _exitMenu;
    QAction* _exitAction;
    QPoint _offset;

    //////////// 主体
    QVBoxLayout* _mainLayout;

    //////////// 顶部
    QHBoxLayout* _topLayout;
    QWidget* _topWidget;
    QLabel* _labelDate;
    QLineEdit* _cityEdit;
    QPushButton* _searchButton;
    void getDate(QString& str);

    //////////// 左侧
    QVBoxLayout* _leftLayout;
    QWidget* _leftWidget;

    QLabel* _weatherIcon;
    QLabel* _temperatureText;
    QLabel* _city;
    QLabel* _weatherText;
    QLabel* _lowHighTemperature;

    QLabel* _coldIndex;

    QLabel* _windIcon;
    QLabel* _windDirection;
    QLabel* _windLevel;

    QLabel* _pM25Icon;
    QLabel* _pM25Text;
    QLabel* _pM25Index;

    QLabel* _humidityIcon;
    QLabel* _humidityText;
    QLabel* _humidityPercent;

    QLabel* _airQualityIcon;
    QLabel* _airQualityText;
    QLabel* _airQualityIndex;

    //////////// 右侧
    QVBoxLayout* _rightLayout;
    QWidget* _rightWidget;

    QList<QLabel*> _weekList;
    QList<QLabel*> _dateList;

    QList<QLabel*> _weatherIconList;
    QList<QLabel*> _weatherTypeList;

    QList<QLabel*> _airQualityList;

    QLabel* _lowTempLineChart;
    QLabel* _highTempLineChart;
    QList<qint8> _lowTemp = {0, 0, 0, 0, 0, 0};
    QList<qint8> _highTemp = {0, 0, 0, 0, 0, 0};

    QList<QLabel*> _windDirectionList;
    QList<QLabel*> _windLevelList;

    WeatherNetWork* _netWork;

private slots:
    void onSearchButtonClick();
};
#endif // WIDGET_H
